package com.yequan.leetcode.string.maxVowels_1456;

/**
 * @author yequan
 * @date 2021/12/31 15:44
 **/
public class MaxVowels {

    public int maxVowels1(String s, int k) {
        if (s == null || "".equals(s)) {
            return 0;
        }
        int sum = 0;
        int max = 0;
        int right = 0;
        while (right < s.length()) {
            sum += isVowels(s.charAt(right));
            right++;
            if (right >= k) {
                max = Math.max(sum, max);
                sum -= isVowels(s.charAt(right - k));
            }
        }
        return max;
    }

    public int maxVowels2(String s, int k) {
        if (s == null || "".equals(s)) {
            return 0;
        }
        int right = 0;
        int sum = 0;
        int max = 0;
        while (right < s.length()) {
            sum += isVowels(s.charAt(right));
            right++;
            if (right >= k) {
                sum = Math.max(sum, max);
                sum -= isVowels(s.charAt(right - k));
            }
        }
        return max;
    }

    private int isVowels(char c) {
        return 'a' == c || 'e' == c || 'i' == c || 'o' == c || 'u' == c ? 1 : 0;
    }

}
